package net.xi.dmhome.controller;

import net.xi.dmhome.entity.Doctor;
import net.xi.dmhome.handler.Result;
import net.xi.dmhome.mapper.DoctorMapper;
import net.xi.dmhome.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: jxhu
 * @Description:医生类信息控制层
 * @Date Created in 2021-02-07 16:07
 * @Modified By:
 */
@RestController
@RequestMapping("/doctor")
public class DoctorController {

    @Autowired
    DoctorMapper doctorMapper;
    @Autowired
    DoctorService doctorService;

    /* @Description: 添加医生信息,@Param:  */
    @PostMapping("/add")
    public Result add(@Validated @RequestBody(required = false) Doctor doctor) throws Exception {

        int insert = doctorMapper.insert(doctor);
        if (insert != 0) {

            System.out.println("添加成功");
            return Result.success(200, "success", insert);
        } else {
            return Result.fail("添加失败");
        }
    }
    /* @Description: 根据id查找医生信息,@Param:  */
    @GetMapping("/findbyid/{uuid}")
    public Result getDoctorById(@PathVariable("uuid") String uuid) throws Exception {
        Doctor doctor = doctorMapper.selectByUserUUid(uuid);


        return Result.success(doctor);

    }
    /* @Description: 编辑医生信息,@Param:  */
    @PutMapping("/edit")
    public Result editUser(@Validated @RequestBody Doctor doctor) throws Exception {
        int update = doctorMapper.updateById(doctor);
        if (update !=0) {

            System.out.println("更改成功");
            return Result.success(200, "success", doctor);
        } else {
            return Result.fail("更改失败");
        }
    }


    /* @Description: 删除医生,@Param:  */
    @DeleteMapping("/delete/{id}")
    public Result deleteDoctor(@PathVariable("id") Integer id){
        int i = doctorMapper.deleteById(id);
        if (i == 1){
            return Result.success("删除成功");
        }else {
            return Result.fail("删除失败");
        }
    }

}
